package service

import (
	"TodoList/cache"
	"TodoList/dao"
	"TodoList/logm"
	"TodoList/serializer"
)

// AddTodoService 管理添加事项的服务
type AddTodoService struct {
	Content string `form:"content" json:"content" binding:"required"`
}

// AddTodo 添加事项
func (service *AddTodoService) AddTodo() serializer.Response {
	// 添加事项
	err, todo := dao.AddTodo(service.Content)
	if err != nil {
		logm.Sad.Println("add task failed:", err)
		return serializer.Response{
			Code:    505,
			Message: "添加事项失败",
			Error:   err.Error(),
		}
	}
	logm.Smile.Println("add task success!")
	//添加累计任务数量
	cache.AddCount()
	return serializer.Response{
		Message: "添加事项成功",
		Data:    todo,
		Code:    0,
	}
}
